#pragma once
#include <iostream>
#include <pthread.h>

class Mutex 
{
public:
    Mutex(pthread_mutex_t* mutex)
    :_mutex(mutex)
    {
        pthread_mutex_init(_mutex, nullptr);
    }
    void lock(){
        pthread_mutex_lock(_mutex);
    }
    void unlock(){
        pthread_mutex_unlock(_mutex);
    }
private:
    pthread_mutex_t* _mutex;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex)
    :_pmtx(mutex){
        _pmtx.lock();
    }
    ~LockGuard(){
        _pmtx.unlock();
    }
private:
    Mutex _pmtx;
};